//
//  DemoCalenderViewController.m
//  ProjectforHDX
//
//  Created by HDX on 16/5/12.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "DemoCalenderViewController.h"
#import "CalendarHomeViewController.h"
#import "TimeNotificationClass.h"

@interface DemoCalenderViewController ()
{

    
    UIView * mainView;
       CalendarHomeViewController *chvc;
    
}
@property(nonatomic,strong)     NSMutableArray * dataArray;
@end

@implementation DemoCalenderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.mBackColor=[UIColor whiteColor];
    self.labnav.text=@"日期选择";
    [self.labnav setFont:NavFontSize];
    [self.labnav setTextColor:[UIColor whiteColor]];
    
    self.dataArray=[[NSMutableArray alloc] init];
    
    chvc = [[CalendarHomeViewController alloc]init];
    chvc.view.frame=CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:chvc.view];
    chvc.pushforwardMoths=1;
    chvc.pfMothsCanSelect=YES;
    chvc.flagMax=1;
    
    NSDate *date=[NSDate date];
    NSString *day= [UtilCheck stringByDate:date dateFormatter:@"yyyy-MM-dd"];
    if(self.day&&self.day.length>4){
        day=self.day;
    }
    [chvc setHotelToDay:270 ToDateforString:day];
    
    __weak typeof(self) weakSelf=self;
 

    chvc.calendarblock = ^(CalendarDayModel *model){
 
        
        if(model.style==CellDayTypeClick)
        {
            
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
            NSDate* date1 = [formatter dateFromString:model.toString];
           NSString *timeSting= [UtilCheck stringByDate:date1 dateFormatter:@"yyyy-MM-dd"];
            
            if(weakSelf.viewblock){
                weakSelf.viewblock(timeSting);
            }
            [weakSelf leftItem:nil];
 
        }
        else
        {
 
        }
        
      
        
    };
    
    // Do any additional setup after loading the view.
}
-(void)mainViewClass:(NSInteger)num
{
    
    [mainView removeFromSuperview];
    
    mainView=[[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-50,self.view.frame.size.width,50)];
    mainView.backgroundColor=[UIColor grayColor];
    [self.view addSubview:mainView];
    
    
    UILabel * lable =[[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    lable.font=[UIFont systemFontOfSize:14.0f];
    lable.textColor=[UIColor whiteColor];
    lable.textAlignment=NSTextAlignmentCenter;
    [mainView addSubview:lable];
    
    
    if(num==0)
    {
        lable.text=@"请选择入住时间";
    }
    if(num==1)
    {
        lable.text=@"请选择离店时间";
        
    }
    if(num==2)
    {
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"YYYY-MM-dd"];
        NSDate* date1 = [formatter dateFromString:[self.dataArray objectAtIndex:0]];
        NSDate* date2 = [formatter dateFromString:[self.dataArray objectAtIndex:1]];
        
        
        NSLog(@"%@",date1);
        NSLog(@"%@",date2);
        
        NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        NSDateComponents *comps = [gregorian components:NSCalendarUnitDay fromDate:date1 toDate:date2  options:0];
        
        int days =(int) [comps day];
        
        
        lable.text=[NSString stringWithFormat:@"%@入住---%@离店 共%d晚",[self.dataArray objectAtIndex:0],[self.dataArray objectAtIndex:1],days];
        
    }
    
    
}

@end
